package com.yueya.business.stay.model;

import java.util.Map;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.yueya.business.senior.model.SeniorBase;
import com.yueya.business.senior.model.SeniorExamination;
import com.yueya.common.util.DateUtil;
import com.yueya.common.util.UUIDGenerator;

import net.sf.json.JSONObject;

/**
 * 入住管理
 * @author todd
 * 
 *
 */
@SuppressWarnings("serial")
public class Stay extends Model<Stay> {
	
	public static  Stay dao = new Stay();
	
	public boolean save(Stay dao) {
		
		dao.set("del_flag", "0");
		dao.set("create_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.save();
	}

	 
    public boolean update(Stay dao) {
    	dao.set("update_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.update();
	}
    
    
   
    
 
  public Stay getDetailById(String id) {
    	String sql = "select * from jg_stay sb ";
		sql += " where sb.del_flag='0' and  sb.stay_id =?  ";
		Stay r = dao.findFirst(sql, id);
		return r;
    }
    
    
	public Page<Stay>  paginate (int pageNumber,int pageSize,JSONObject jo) {
    	String select = "select se.*,sb.name,sb.id_card ";
		StringBuffer sql = new StringBuffer(
				" from jg_stay se , v_senior_base sb where sb.del_flag='0' and se.senior_id = sb.senior_id ");
		// 名字
		if (jo.containsKey("name")) {
			String name = jo.getString("name");
			if (StrKit.notBlank(name)) {
				sql.append(" and (sb.name like '%" + name + "%' or sb.id_card like  '%" + name + "%'  )");
			}
		}
		sql.append(" order by se.create_time desc");
		return dao.paginate(pageNumber, pageSize, select, sql.toString());
    }
    
    
}
